/**
 * Created by longgs on 2018-7-18.
 */
angular.module('MetronicApp').controller('AlgorithmStatisticController',
    ['$rootScope', '$scope', '$state', '$uibModal', '$stateParams', 'toastr', 'StatisticService', 'EnumService',
        function ($rootScope, $scope, $state, $uibModal, $stateParams, toastr, StatisticService, EnumService) {
            $scope.$on('$viewContentLoaded', function () {
                App.initAjax();
                $rootScope.settings.layout.pageBodySolid = true;
                $rootScope.settings.layout.pageSidebarClosed = false;
            });


            $scope.condition = {};
            $scope.statisticData = EnumService.get('years');
            $scope.area=EnumService.get('area');
          //  $scope.model.years = $scope.statisticData[1];
            //获取ng-table表头
            $scope.columns = StatisticService.getSchema();

            $scope.pageable = StatisticService.getPageable();
            $scope.$watch('pageable.size', function (newVal, oldVal) {
                if (newVal === oldVal) return;
                StatisticService.setSize(newVal);
                $scope.list();
            });

            $scope.$watch('pageable.number', function (newVal, oldVal) {
                if (newVal === oldVal) return;
                StatisticService.setStoredPage(newVal);
                $scope.list();
            });

            //企业画像表头五个tab数据获取
            $scope.tabItemList = [
                {
                    "name": "标签体系",
                    "router": "labelSystemList",
                    "selected": false
                },
                {
                    "name": "企业信息",
                    "router": "informationList",
                    "selected": false
                },
                {
                    "name": "挖掘算法",
                    "router": "algorithmList",
                    "selected": true
                },
                {
                    "name": "企业画像",
                    "router": "businessPortraitList",
                    "selected": false
                },
                {
                    "name": "标签检索",
                    "router": "labelRetrievalList",
                    "selected": false
                }
            ]

            $scope.list = function () {
                StatisticService.putSearchParams({
                    search: $scope.condition.search
                });
                StatisticService.list(function (res) {
                    if ('success' === res.status) {
                        $scope.rows = res.data;
                        $scope.pageable = res.pageable;
                    } else {
                        for (var i = 0; i < res.errors.length; i++) {
                            toastr.error(res.errors[i].errmsg, "数据获取失败");
                        }
                    }
                });
            };

            var gotoFirstPage = function () {
                StatisticService.setStoredPage(0);
                $scope.list();
                StatisticService.clearSearchParams();
            };
            gotoFirstPage();


            //返回
            $scope.back = function () {

                $state.go('algorithmList');
            };
            //详情
            if ($scope.id) {
                StatisticService.get($scope.id).$promise.then(function (result) {
                    $scope.model = result.data;
                });
            }
        }
    ]
);